import datetime
import random

money = 500  # 钱包
shopcar = []  # 购物车
shop = ['梨', '4090显卡', 'ps5', '小霸王', '雷碧']  # 商品栏
price = [5, 14999, 3999, 150,3]  # 价格栏
privilege = random.randint(0,4)
discount =random.randint(9,10)
accept=0      #####退货许可
print('恭喜获得{}{} 折优惠券'.format(shop[privilege],discount))
price[privilege]=price[privilege]*10/discount
while 1:
    goods = input("要买什么呢？")
    if  accept>0:
        if goods in ['T','t']:
            delete=input("请输入要退款的商品")
            shopcar.remove(delete)
            money+=price[shop.index(delete)]
            print("退货成功")
            continue
    if goods in ['q','Q']:
        print("结束购物")
        break
    if goods in shop:
        i = shop.index(goods)
        print("有", goods, "价格为", price[i])
        print("您的余额为", money)
        if money >= price[i]:
            shopcar.append(goods)
            money -= price[i]
            print("购买成功,您的余额为", money)
            accept+=1
        else:
            print('穷鬼，钱不够！请到其他超市购买！')
    else:
        print("没有这个商品，别瞎弄！")
print('您购买的商品有:')
sum=0
for i in shopcar:
    print(i,'花费:',price[shop.index(i)],    end='\t')
    sum+=price[shop.index(i)]
print("总花费：",sum)
print("您的余额:",money)
print("购物时间:",datetime.datetime.now())

